<!-- 质检溯源的首页组件 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="批次号" prop="batchCode">
        <el-input
          v-model="queryParams.batchCode"
          placeholder="请输入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户编码" prop="customerCode">
        <el-input
          v-model="queryParams.customerCode"
          placeholder="请输入客户编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="lotTraceabilityList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="出货单ID" align="center" prop="sales_id" v-if="false" />
      <el-table-column label="接收人" align="center" prop="recipient" />
      <el-table-column label="客户编码" align="center" prop="customer_code" />
      <el-table-column label="客户名称" align="center" prop="customer_name" />
      <el-table-column label="收货人" align="center" prop="recipient" />
      <el-table-column label="联系电话" align="center" prop="tel" />
      <el-table-column label="收货地址" align="center" prop="address" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['qc:lotTraceability:view']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listLotTraceability } from "@/api/qc/PendingTasks";

export default {
  name: 'ZlLotTraceability',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 质检溯源表格数据
      lotTraceabilityList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchCode: null,
        productCode: null,
        customerCode: null
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询质检溯源列表 */
    getList() {
      this.loading = true;
      listLotTraceability(this.queryParams).then(response => {
        this.lotTraceabilityList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 多选框选中数据 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.$router.push({
        path: "/qc/LotTraceability/detail",
        query: { salesId: row.sales_id, productCode: row.product_code }
      });
    }
  }
}
</script>
